window.addEventListener('load', function () {
    $(function () {
        $('.menu_item').hover(function () {

            $(this).children('.sub_menu').stop().slideToggle(200)

            $('.white_background ').stop().fadeToggle(100);
       
        })

        $(function () {
            $('.menu_item').mouseover(function () {
                $('.logo img').attr("src", "./images/common-images/logo.png")
                

                $(this).css({
                    height:350
                }).siblings().css({
                    height:350
                })

                $('.header_wrap.header_white .header_content .menu_item .text').css({
                    color:"#555"
                })
    
                $('.header_wrap.header_white .header_content .lang_wrap .text').css({
                    color:"#555"
                })
    
                $('.header_wrap.header_white .header_content .lang_wrap .lang_logo').css("background-image","url(./images/common-images/lang-logo-gray.@cb0222f8.png)")

                
            })
            $('.menu_item').mouseout(function () {
                $('.logo img').attr("src","./images/common-images/logo-white.@f94af395.png")

                $('.header_wrap.header_white .header_content .menu_item .text').css({
                    color:"#fff"
                })


                $(this).css({
                    height:90
                }).siblings().css({
                    height:90
                })
    
                $('.header_wrap.header_white .header_content .lang_wrap .text').css({
                    color:"#fff"
                })
    
                $('.header_wrap.header_white .header_content .lang_wrap .lang_logo').css("background-image","url(./images/common-images/lang-logo-white.png)")    
            })
        })


        $('.tab_list1 li  ').click(function () {
            $(this).css({
                "border-bottom": "4px solid red"
            }).siblings('li').css({
                "border-bottom": ""
            })
        })
    })

    $(function () {
        $(".tab_list li").click(function () {
            $(this).addClass("bdb_red").siblings().removeClass("bdb_red");
            var index = $(this).index();
            console.log(index);
            $(".tab_con .item").eq(index).show().siblings().hide(); 
        });
    })
    

    var div = document.querySelector(".carousel");
    var ul = document.querySelector(".ul");
    var a = document.querySelectorAll(".as");
    var dot = document.querySelector(".dot");
    // 创建小圆点
    for (var i = 0; i < ul.children.length - 1; i++) {
        var newSpan = document.createElement("span");
        newSpan.innerHTML = i + 1;
        newSpan.setAttribute("data-index", i);
        dot.appendChild(newSpan);
    }
    // 给第一个圆圈设置默认样式
    var span = dot.children;
    var timer = null;
    span[0].className = "selected";
    // 显示左右按钮
    div.addEventListener("mouseover", function () {
        a[0].style.display = "block";
        a[1].style.display = "block";
        clearInterval(timer);
    });
    div.addEventListener("mouseout", function () {
        a[0].style.display = "none";
        a[1].style.display = "none";
        // 自动播放
        timer = setInterval(function () {
            a[1].click();
        }, 500);
    });
    // 按钮功能,右面
    var tab = 0;
    var k = 0;
    var flag = true;

    a[1].addEventListener("click", function () {
        if (flag) {
            flag = false;
            console.log(flag);
            if (tab == 8) {
                ul.style.left = 0;
                tab = 0;
            }
            k++;
            tab++;
            go(ul, -1530 * tab, function () {
                flag = true;
            });
            // 控制小圆点类名
            if (k > 7) {
                k = 0;

            }
            for (var j = 0; j < span.length; j++) {
                span[j].className = "";
            }
            span[k].className = "selected";
        }
    });
    // 左面同理
    a[0].addEventListener("click", function () {
        if (flag) {
            flag = false;
            if (tab == 0) {
                ul.style.left = -1530 * 8 + "px";

                tab = 8;
            }
            tab--;
            k--;
            go(ul, -1530 * tab, function () {
                flag = true;
            });
            if (k < 0) {
                k = 7
            }
            for (var j = 0; j < span.length; j++) {
                span[j].className = "";
            }
            span[k].className = "selected";
        }
    });
    // 给小圆点添加事件
    for (var i = 0; i < span.length; i++) {
        span[i].addEventListener("click", function () {
            tab = k = this.getAttribute("data-index");
            go(ul, -tab * 1530);

            for (var j = 0; j < span.length; j++) {
                span[j].className = "";
            }
            span[k].className = "selected";
        })
    }
    // 自动播放
    var timer = setInterval(function () {
        a[1].click();
    }, 500);

    function go(obj, target, fn) {
        clearInterval(obj.timer);
        obj.timer = setInterval(function () {
            var step = (target - obj.offsetLeft) / 10;
            step = step > 0 ? Math.ceil(step) : Math.floor(step);
            obj.style.left = obj.offsetLeft + step + "px";
            if (obj.offsetLeft == target) {
                clearInterval(obj.timer);
                fn && fn();
            }
        }, 20)

    }
   
    var btn = document.getElementById('btn');
    btn.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/business#user';
    })
    btn1.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/business#industry';
    })
    var btn2 = document.getElementById('btn2');
    btn2.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/business#core';
    })
    var btns = document.getElementById('btns');
    btns.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/media#dynamic';
    })
    var aaas = document.querySelector('.dynamica')
    aaas.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/media/314';

    })
    var bbbs = document.querySelector('.dynamicb')
    bbbs.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/media/313';
    })
    var cccs = document.querySelector('.dynamicc')
    cccs.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/media/312';
    })
    var ddds = document.querySelector('.dynamicd')
    ddds.addEventListener('click', function () {
        location.href = 'https://www.meitu.com/zh/media/312';
    })
    


})

function jumpPage1() {
     window.open("https://xiuxiu.meitu.com/");
 }

 function jumpPage2() {
     window.open("http://meiyan.meipai.com/");
 }

 function jumpPage3() {
     window.open("https: //www.meipai.com/");
 }

 function jumpPage4() {
     window.open("https://eve.meitu.com/");
 }

 function jumpPage5() {
     window.open("https://yunxiu.meitu.com/download");
 }

 function jumpPage6() {
     window.open("http://mtlab.meitu.com/");
 }